<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>选择人员</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" type="text/css" href="../../css/sm.min.css">
    <link rel="stylesheet" type="text/css" href="../../css/normal.css" />
    <link rel="stylesheet" type="text/css" href="../../css/chooseSaler.css" />
</head>

<body>
    <div class="page allWarp">
        <div class="content">
            <div class="salerList">
                <ul>
                    <li v-for="item in usrData" onclick="chooseUser()" :data-userId = "item.userId" :data-loginName = "item.loginName" :data-nickname= "item.nickname">
                        <span v-text="item.nickname"></span>
                        <span class="left10" v-text="item.loginName"></span>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <script type="text/javascript" src="../../js/zepto.js"></script>
    <script type="text/javascript" src="../../js/sm.min.js"></script>
    <script type="text/javascript" src="../../js/vue.min.js"></script>
    <script type="text/javascript" src="../../js/ajax.js"></script>
    <script type="text/javascript" src="../../js/back.js"></script>
    <script type="text/javascript">
        var isNewProject = GetQueryString("isNewProject");//判断是否为新建project
        var isNewNode = GetQueryString("isNewNode");//判断是否为新建节点
        var nodeCode = GetQueryString("nodeCode");
        var projectCode = GetQueryString("projectCode");
        var come = GetQueryString("come");
        var role = GetQueryString("role");
        var userType = GetQueryString("userType");
        var demo = new Vue({
            el: '.allWarp',
            data: {
                usrData: '',
            },
            beforeCreate: function() {
                userList();
            }
        })
        // 销售列表
        function userList(){
            var params = {};
            params.userType = userType;
            kfAjaxGet.userList(params, function(json) {
                if (json.code == 200) {
                    demo.usrData = json.data;
                    // console.log(json)
                } else if (checkcode(json.code)) {

                } else {
                    $.toast(json.message);
                }
            })
        }
        function chooseUser(){
            var _that = $(event.currentTarget);
            var salerUid = _that.attr("data-userId");
            var salerName = _that.attr("data-nickname");
            var salerPhone = _that.attr("data-loginName");
            var nodeSaler = JSON.parse(sessionStorage.getItem('nodeSaler_data'))
            console.log(nodeSaler)
            if (nodeSaler == null || nodeSaler == []) {
                nodeSaler = [];
            }else{
                nodeSaler = nodeSaler;
                console.log(nodeSaler)
            }
            var data ={
                'dutyUserId':salerUid,
                'dutyUser':salerName,
                'dutyPhone':salerPhone
            }
            for (var i=0;i<nodeSaler.length;i++){
                if (nodeSaler[i].dutyUserId == salerUid) {
                    $.toast("请勿重复选择相同人员");
                    return false;
                }
            }

            if(isNewProject != ''){
                sessionStorage.setItem('projectSaler_data', JSON.stringify(data))
                window.location = 'creatProject.html?salerName='+salerName+'&salerUid='+salerUid+'&phone='+salerPhone+'&role='+role;
            }
            if(isNewNode != ''){
                nodeSaler.push(data);
                console.log(nodeSaler)
                sessionStorage.setItem('nodeSaler_data', JSON.stringify(nodeSaler))
                window.location = 'addPoint.html?isNewNode='+isNewNode+'&projectCode='+projectCode+'&nodeCode='+nodeCode+'&come='+come+'&role='+role;
            }
        }

        $(function(){
            $('#gohome').on('click',function(){
                window.location = 'myProject.html?role='+role;
            })
        })
    </script>
</body>
</html>